import static org.junit.Assert.*;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class ObjectListTest {
	ObjectList workerList;
	ObjectList otherList;
	Worker a;
	Worker b;
	Worker c;
	Worker otherA;
	Worker otherB;
	Worker otherC;

	@Before
	public void setUp() throws Exception {
		workerList = new ObjectList();
		a = new Worker("a", "a");
		b = new Worker("b", "b");
		c = new Worker("c", "c");
		otherA = new Worker("a", "a");
		otherB = new Worker("b", "b");
		otherC = new Worker("c", "c");
	}

	@Test
	public void notFoundOnEmptyList() {
		int foundPosition = workerList.indexOf(a);
		assertTrue(foundPosition == -1);
	}

	@Test
	public void notFoundOnList() {
		workerList.add(a);
		workerList.add(b);
		workerList.add(c);
		Worker d = new Worker("d", "d");

		int foundPosition = workerList.indexOf(d);
		assertTrue(foundPosition == -1);
	}

	@Test
	public void foundOnList() {
		workerList.add(a);
		workerList.add(b);

		int foundPosition = workerList.indexOf(b);
		assertTrue(foundPosition == 1);
	}

	@Test
	public void foundOnFullList() {
		workerList.add(a);
		workerList.add(b);
		workerList.add(c);

		int foundPosition = workerList.indexOf(c);
		assertTrue(foundPosition == 2);
	}

	@Test
	public void insertEmptyAtBeginning() {
		workerList.add(a);
		workerList.add(b);
		workerList.add(c);

		ObjectList fromList = new ObjectList();

		workerList.insertAll(0, fromList);

		Assert.assertTrue(workerList.size() == 3);

		Assert.assertTrue(workerList.getPosition(0) == this.a);
		Assert.assertTrue(workerList.getPosition(1) == this.b);
		Assert.assertTrue(workerList.getPosition(2) == this.c);

	}

	@Test
	public void insertEmptyAtEnd() {
		workerList.add(a);
		workerList.add(b);
		workerList.add(c);

		ObjectList fromList = new ObjectList();

		workerList.insertAll(4, fromList);

		Assert.assertTrue(workerList.size() == 3);

		Assert.assertTrue(workerList.getPosition(0) == this.a);
		Assert.assertTrue(workerList.getPosition(1) == this.b);
		Assert.assertTrue(workerList.getPosition(2) == this.c);

	}

	@Test
	public void insertListAtBeginning() {
		workerList.add(a);
		workerList.add(b);
		workerList.add(c);
		otherList.add(otherA);
		otherList.add(otherB);
		otherList.add(otherC);
		workerList.insertAll(0, otherList);

		Assert.assertTrue(workerList.size() == 6);

		Assert.assertTrue(workerList.getPosition(0) == otherA);
		Assert.assertTrue(workerList.getPosition(1) == otherB);
		Assert.assertTrue(workerList.getPosition(2) == otherC);

		Assert.assertTrue(workerList.getPosition(3) == this.a);
		Assert.assertTrue(workerList.getPosition(4) == this.b);
		Assert.assertTrue(workerList.getPosition(5) == this.c);

	}
	
	@Test
	public void insertListAtEnd() {
		workerList.add(a);
		workerList.add(b);
		workerList.add(c);
		otherList.add(otherA);
		otherList.add(otherB);
		otherList.add(otherC);
		workerList.insertAll(2, otherList);

		Assert.assertTrue(workerList.size() == 6);

		Assert.assertTrue(workerList.getPosition(0) == otherA);
		Assert.assertTrue(workerList.getPosition(1) == otherB);
		Assert.assertTrue(workerList.getPosition(2) == otherC);

		Assert.assertTrue(workerList.getPosition(3) == this.a);
		Assert.assertTrue(workerList.getPosition(4) == this.b);
		Assert.assertTrue(workerList.getPosition(5) == this.c);
	}

}
